<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('商城列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <div id="result"></div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/device";

        $(function() {
            var options = {
                url: prefix + "/queryDeviceList",
                updateUrl: prefix + "/purchase/{id}",
                sortName: "deviceSort",
                modalName: "购买",
                columns: [{
                    checkbox: false
                },
                    {
                        field: 'deviceId',
                        title: '设备编号'
                    },
                    {
                        field: 'deviceName',
                        title: '设备名称',
                        sortable: true
                    },
                    {
                        field: 'deviceType',
                        title: '设备类别',
                        sortable: true,
                        formatter: function (value, row, index) {
                            var request = $.ajax({
                                type: "post",
                                url: prefix + "/deviceTypeTools",
                                async: false,
                                data: {
                                    "deviceId": row.deviceId
                                }
                            });
                            var text = request.responseText;
                            var json = JSON.parse(text);
                            return json.dictLabel;
                        }
                    },
                    {
                        field: 'deviceSort',
                        title: '显示顺序',
                        sortable: true
                    },
                    {
                        field: 'price',
                        title: '价格(￥)',
                        sortable: true
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        sortable: true
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.purchase(\'' + row.deviceId + '\')"><i class="fa fa-edit"></i>购买</a> ');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });

        // function purchase(id) {
        //     $.modal.confirm("确认要购买该设备吗？", function() {
        //         $.operate.post(prefix + "/purchase", { "deviceId": id });
        //     })
        // }
    </script>
</body>
</html>
